<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class SIHI extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('muser');
   $this->load->library('form_validation');
   $this->load->library('pagination');
 }
 function index(){
 	 if ($this->input->post('SIHI_ID')!=NULL)
 	 {
 	 	$this->form_validation->set_rules('SIHI_ID','SIHI_ID','trim|integer|callback_check_SIHI');				
		if ($this->form_validation->run()==FALSE){
			$data['error']='SIHI_ID is existed !';
		}else{		
			$DT=array(
					"SIHI_ID"=>$this->input->post('SIHI_ID'),
					"SI_Book_No"=>$this->input->post('SI_Book_No'),
					"IssuedDate1"=>$this->input->post('IssuedDate1'),
					"HI_Card_No"=>$this->input->post('HI_Card_No'),
					"IssuedDate2"=>$this->input->post('IssuedDate2'),
					"ExpiredDate"=>$this->input->post('ExpiredDate'),
					"RegisteredHospital"=>$this->input->post('RegisteredHospital')
			);
			$this->muser->addData('SIHI',$DT);
			$data['error']='Insert successful!';
		}		
 	 }	 
 	 $config['base_url'] = base_url().'SIHI/index'; 
	 $config['total_rows'] = $this->muser->num_rows('SIHI');
	 
	 $config['per_page'] = 10; // xác định số record ở mỗi trang  
     $config['uri_segment'] = 3; // xác định segment chứa page number  
	 $this->pagination->initialize($config); 
	 $data['result']=$this->muser->getalldata('SIHI',$config['per_page'],$this->uri->segment(3));	
	 
	 $this->load->view('_header');
     $this->load->view('SIHI/SIHI_view',$data); 
     $this->load->view('_footer');
 }
 function delete($SIHI_ID){ 	
	$er=$this->muser->delColumn('SIHI','SIHI_ID',$SIHI_ID);
	redirect('SIHI/index');	
 }
 function edit1 ()
 {
 	$DT=array(
					"SIHI_ID"=>$this->input->post('SIHI_ID'),
					"SI_Book_No"=>$this->input->post('SI_Book_No'),
					"IssuedDate1"=>$this->input->post('IssuedDate1'),
					"HI_Card_No"=>$this->input->post('HI_Card_No'),
					"IssuedDate2"=>$this->input->post('IssuedDate2'),
					"ExpiredDate"=>$this->input->post('ExpiredDate'),
					"RegisteredHospital"=>$this->input->post('RegisteredHospital')
			);
	$this->muser->updateData('SIHI','SIHI_ID',$DT['SIHI_ID'],$DT);
	$data['error']='Edit successful!';	 	
	redirect('SIHI/index');		
 } 
 function edit($str)
 {	
 	$result=$this->muser->getRdata('SIHI','SIHI_ID',$str);
	$data['result']=$result;	
 	$this->load->view('_header');
	$this->load->view('SIHI/editSIHI_view',$data);	
	$this->load->view('_footer');
 }
 
 function check_SIHI($str){
 		return $this->muser->checkData('SIHI','SIHI_ID',$str);		
 }
}